package app.controller;

import app.command.EnumCall;
import app.msg.CommonMessage;
import app.msg.RoleMessage;
import app.vo.GachaVo;
import app.vo.User;
import org.ricks.common.Context;
import org.ricks.ioc.Bean;
import org.ricks.net.ActionMethod;
import org.ricks.log.Logger;
import org.ricks.utils.RandomUtil;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author ：demon-chen
 * @date ：Created in 2019/12/18 下午3:16
 * @description：
 * @modified By：
 * @version: $
 */
@Bean
public class TestController {

//    public static final TestController testController = new TestController();


     private AtomicLong count = new AtomicLong(0);
     private volatile long startTime =  0;
     private AtomicBoolean start = new AtomicBoolean(true);
//    @HttpMapping(value = "test")
//    public void test(HttpResponse response){
//        Logger.info(" test.......");
//        response.redirect("www.baidu.com");
//    }

    @ActionMethod(messageId = 1)
    public void test(Context context) {
//        System.err.println("进入  test  ,,,,,,,,1000......");
        long num = count.incrementAndGet();
        System.err.println("进入  test  ,,,,,,,,"+ num+"......");
//        if(num == 1) {
//            startTime = System.currentTimeMillis();
//            Logger.info("jdk aio  test....... time:{}",startTime);
//        }
//        if(System.currentTimeMillis() - startTime > 1000  && start.get()) {
//            start.set(false);
//            Logger.info("1秒承载  count:{}",count);
//        }
//        if(num == 1000000) {
//            Logger.info("jdk aio  test....... time:{}",System.currentTimeMillis());
//        }
//        CardData cardData = Optional.of(DataContext.getCard(10010000)).orElse(new CardData());
//        System.err.println(" cardId: " + cardData.getCardId() + " and AdvanceID: "+ cardData.getAdvanceID() + " and AdvanceValue: " + cardData.getAdvanceValue() );
//        context.send();
//        KcpSeesion kcpSeesion = (KcpSeesion)context.getSession();
//        System.err.println("conv:" + kcpSeesion.getKcp().getConv() + " and 请求次数 num:" + num);
//        System.err.println("进入请求，。。。。。");
//        context.send();
    }

    @ActionMethod(messageId = 100)
    public void test00(Context context) {
        System.err.println("进入cmd = 100  test  ,,,,,,,,,");
        long num = count.incrementAndGet();
//        if(num == 1) {
//            startTime = System.currentTimeMillis();
//            Logger.info("jdk aio  test....... time:{}",startTime);
//        }
//        if(System.currentTimeMillis() - startTime > 1000  && start.get()) {
//            start.set(false);
//            Logger.info("1秒承载  count:{}",count);
//        }
//        if(num == 1000000) {
//            Logger.info("jdk aio  test....... time:{}",System.currentTimeMillis());
//        }
//        CardData cardData = Optional.of(DataContext.getCard(10010000)).orElse(new CardData());
//        System.err.println(" cardId: " + cardData.getCardId() + " and AdvanceID: "+ cardData.getAdvanceID() + " and AdvanceValue: " + cardData.getAdvanceValue() );
//        context.send();
//        KcpSeesion kcpSeesion = (KcpSeesion)context.getSession();
//        System.err.println("conv:" + kcpSeesion.getKcp().getConv() + " and 请求次数 num:" + num);
//        context.send();

        context.send(RoleMessage.createRoleInfoMsg());
        context.send(CommonMessage.getSimpleBoolValue());
    }

    @ActionMethod(messageId = 900)
    public void test001(Context context) {
//        System.err.println("进入cmd = 101  test  ,,,,,,,,,");
//        long num = count.incrementAndGet();
//        if(num == 1) {
//            startTime = System.currentTimeMillis();
//            Logger.info("jdk aio  test....... time:{}",startTime);
//        }
//        if(System.currentTimeMillis() - startTime > 1000  && start.get()) {
//            start.set(false);
//            Logger.info("1秒承载  count:{}",count);
//        }
//        if(num == 1000000) {
//            Logger.info("jdk aio  test....... time:{}",System.currentTimeMillis());
//        }
//        CardData cardData = Optional.of(DataContext.getCard(10010000)).orElse(new CardData());
//        System.err.println(" cardId: " + cardData.getCardId() + " and AdvanceID: "+ cardData.getAdvanceID() + " and AdvanceValue: " + cardData.getAdvanceValue() );
//        context.send();
//        KcpSeesion kcpSeesion = (KcpSeesion)context.getSession();
//        System.err.println("conv:" + kcpSeesion.getKcp().getConv() + " and 请求次数 num:" + num);
        context.send();
    }

    @ActionMethod(messageId = EnumCall.APP_CONTROLLER_TESTCONTROLLER_TESTUSERDB2)
    public void testUserDb(Context context) {
        long num = count.incrementAndGet();
        Logger.info("开始保存数据。。。。。。。。" + num);
        User user = new User();
        user.setId(3312034310411780130L);
        user.setAge(18);
        user.setBindDiamond(10000);
        user.setCookingExp(0);
        user.setCookingLv(1);
        user.setDuration(1);
        user.setCreateTime(System.currentTimeMillis());
        user.setFinalCityId(1000);
        user.setGold(1000);
        user.setGreetings("你好，demon !");
        user.setHeadIcon(10000);
        user.setLv(1);
        user.setOpenId("demon");
        user.setRoleId(RandomUtil.randomLong());
        user.setRoleName("demon_is_god");
        user.setSendGift(111);
        user.update();
//        context.send();
    }


    @ActionMethod(messageId = 3)
    public void tesGachaDb(Context context) {
        GachaVo gachaVo = new GachaVo();
        gachaVo.setGachaId(18);
        gachaVo.setGachaNum(10000);
        gachaVo.setGachaName("新手卡池");
        gachaVo.setGachaType(1);
        gachaVo.setRoleId(RandomUtil.randomLong());
        gachaVo.save();
//        context.send();
    }

    @ActionMethod(messageId = 4)
    public void demon(Context context) {
        GachaVo gachaVo = new GachaVo();
        gachaVo.setGachaId(18);
        gachaVo.setGachaNum(10000);
        gachaVo.setGachaName("新手卡池");
        gachaVo.setGachaType(1);
        gachaVo.setRoleId(RandomUtil.randomLong());
        gachaVo.save();
//        context.send();
    }


//    @HttpMapping(value = "a")
//    public void a(HttpResponse response){
//        Logger.info(" test.......");
//        response.sendHtml("https://www.baidu.com");
//    }

}
